/*************************************************************************
	> File Name: 234.回文链表_v1.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 四  9/ 2 20:12:51 2021
 ************************************************************************/

//方法一：
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

#define MAX_N 100000
int arr[MAX_N + 5];

bool isPalindrome(struct ListNode* head){
    //数组保存每个节点的值，然后用双指针遍历数组
    if (head == NULL || head->next == NULL) return true;
    struct ListNode *p = head;
    int k = 0;
    while (p) {
        arr[k++] = p->val;
        p = p->next;
    }

    for (int i = 0, j = k - 1; i < j; i++, j--) {
        if (arr[i] != arr[j]) return false;
    }
    return true;
}
